package com.mgs.product.tagger.ui.dto
{
	import com.mgs.product.tagger.model.Axis;
	import com.mgs.product.tagger.model.Classifiable;
	import com.mgs.product.tagger.model.Document;
	import com.mgs.product.tagger.model.Segment;
	
	import mx.collections.ArrayList;

	public class DtoFactory
	{
		public function DtoFactory()
		{
		}
		
		public static function createCell(document:Document):CellUI
		{
			var cell:CellUI = new CellUI();
			cell.descriptionDocument = document;
			cell.description = document == null || document.content == null ? "" : document.content;
			return cell;
		}
		
		public static function createDefaultAxis():AxisUI
		{
			var axis:Axis = new Axis();
			axis.name = "Nouvel Axe";
			axis.segments = new Vector.<Segment>();
			axis.tags = new Vector.<Segment>();
			return createAxis(axis);
		}
		
		public static function createDefaultSegment(axis:AxisUI):SegmentUI
		{
			// create segment.
			var segment:Segment = new Segment();
			segment.axis = axis.axis;
			segment.name = "segment " + (axis.segments.length + 1);
			segment.taggedElements = new Vector.<Classifiable>();
			axis.axis.segments.push(segment);
			
			var segmentUI:SegmentUI = createSegment(segment);
			axis.segments.addItem(segmentUI);
			return segmentUI;
		}
		
		public static function createDocument(document:Document):DocumentUI
		{
			var docUI:DocumentUI = new DocumentUI();
			docUI.document = document;
			return docUI;
		}
		public static function createDefaultDocument():DocumentUI
		{
			var doc:Document = new Document();
			doc.name = "NewDocument.txt";
			doc.tags = new Vector.<Segment>();
			return createDocument(doc);
		}
		public static function createAxis(axis:Axis):AxisUI
		{
			var axisUI:AxisUI = new AxisUI();
			axisUI.axis = axis;
			axisUI.segments = new ArrayList();
			axisUI.selectedSegments = new ArrayList();
			for each(var s:Segment in axis.segments)
			{
				var sui:SegmentUI = new SegmentUI();
				sui.segment = s;
				axisUI.segments.addItem(sui);
			}
			return axisUI;
		}
		public static function createSegment(segment:Segment):SegmentUI
		{
			var segmentUI:SegmentUI = new SegmentUI();
			segmentUI.segment = segment;
			return segmentUI;
		}
	}
}